from . import main
from .controllers import Employee
from flask import jsonify

@main.route('/')
def inext():
    return 'Hello, this is Flask Restufl Demo.'


@main.route('/employees')
def listEmployees():
    emp = Employee()
    employees = emp.listAll()

    result = []
    for employee in employees:
        result.append(employee.to_json())
    return jsonify(result), 200

@main.route('/employees/create', methods=['POST'])
def createEmployee():
    emp = Employee()
    result = emp.create()
    return jsonify(result['desc']), result['code']

@main.route('/employees/<empId>', methods=['PUT'])
def updateEmployee(empId):
    emp = Employee()
    result = emp.update(empId)
    return jsonify({'desc': result['desc']}), result['code']

@main.route('/employees/<empId>', methods=['DELETE'])
def deleteEmployee(empId):
    emp = Employee()
    result = emp.delete(empId)
    return jsonify({'desc': result['desc']}), result['code']